#ifndef _COMMON_H_H
#define _COMMON_H_H

#define FixedPriority		3		//  all task priority must be 3

#ifndef FALSE
#define FALSE	0
#endif

#ifndef TRUE
#define TRUE	1	
#endif

#ifndef NULL
#define NULL 0x0
#endif

typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef signed int s32;
typedef signed short s16;
typedef signed char s8;
typedef volatile unsigned int vu32;
typedef unsigned int   BOOLEAN;

#define  ARRAY_SIZE(x)	(sizeof(x)/sizeof(x[0]))


//when soft release, must close MACRO: MDEBUG
#define MDEBUG

#define SOFT_VER	"s600_app_v1.0.0"

#ifdef MDEBUG	 
#define	DEBUG_UART     MML_UART_DEV1
#define	SHELL_DEBUG		1
#define   MAGC_DEBUG		1
#define   ICC_DEBUG			1
#define   TIMER_DEBUG		1
#define   RAND_DEBUG		1
#define   RTC_DEBUG			1
#define	SYS_DEBUG			0
#define	MAIN_DEBUG		1
#define	NVSRAM_DEBUG		1
#define  	_COM_DEBUG 		1
#define 	UCL_DEBUG			1
#define 	IAP_DEBUG			1
#define 	MON_DEBUG			1
#define 	USB_DEBUG			0
#define 	USBE_DEBUG			1
#define 	HOSTE_DEBUG		1
#define 	SPI_DEBUG			1

#endif

#if _COM_DEBUG > 0
#define   comm_debug         lite_printf
#else 
#define   comm_debug(fmt,...) 	;
#endif

#define 	SYS_AES_MAGIC		(0xe2c3f3ab)
typedef enum{
	SYS_ERR_IDlE = 0x00,	// sys status init
	SYS_ERR_APP,			// check app para error
	SYS_ERR_RTC,			// rtc not init
	SYS_ERR_DRS,			// DRS triggered 
	SYS_ERR_AES,			// aes key area not init
	SYS_ERR_KEY,			// not store secret key
	SYS_ERR_PARA,			// check sys para error
	SYS_USER				// all above ok
}SYS_MODE;


#define QElemType u32

typedef struct QNode
{
	QElemType data;			// store pointer addr
	struct QNode *next;
}QNode,*QueuePtr;
 
typedef struct
{
	QueuePtr front,rear;  
	u16 item;
}LinkQueue;



#include "config.h"
#include "errors.h"
#include "string.h"
#include "stdarg.h" 
#include "mml.h" 
#include "mml_gcr.h"
#include "mml_uart.h"
#include "mml_uart_regs.h"
#include "mml_gpio.h"
#include "mml_gpio_regs.h"
#include "mml_spi.h"
#include "mml_spi_regs.h"
#include "mml_tmr.h"
#include "mml_tmr_regs.h"
#include "mml_nvic_regs.h"
#include "mml_gcr_regs.h"
#include "mml_gcr.h"
#include "mml_gpio.h"
#include "mml_intc.h"
#include "mml_tmr_regs.h"
#include "mml_tmr.h"
#include "mml_uart_regs.h"
#include "mml_uart.h"
#include "mml_mcr.h"
#include "mml_sc.h"
#include "mml_sc_dev.h"
#include "mml_sc.h"
#include "mml_sc_dev.h"
#include "mml_mcr.h"
#include "mml_gcr_regs.h"
#include "mml_skbd.h"
#include "mml_trng_regs.h"
#include "mml_sflc.h"
#include "mml_rtc_regs.h"
#include "Mml_crypto_regs.h"
#include "Mml_scbr_regs.h"


#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "portmacro.h"
#include "semphr.h"
#include "fifo.h"
#include "cobra_defines.h"
#include "cobra_macros.h"
#include "cobra_functions.h"
#include "cobra_defines.h"
#include "cobra_macros.h"
#include "cobra_functions.h"
#include "time.h"

#include "emv_config.h"
#include "emv_loopback.h"
#include "emv_slot.h"
#include "emv_timer.h"
#include "libemv.h"

#include "ucl_config.h"
#include "ucl_defs.h"
#include "ucl_retdefs.h"
#include "ucl_types.h"
#include "ucl_sys.h"
#include "ucl_stack.h"
#include "ucl_info.h"
#include "ucl_des.h"
#include "ucl_3des.h"

#include "syspara.h"
#include "rtc.h"
#include "main.h"
#include "shell.h"
#include "uart_config.h"
#include "printf_lite.h"
#include "private.h"
#include "icc.h"
#include "string.h"
#include "private.h"
#include "printf_lite.h"
#include "magc.h"
#include "timerf.h"
#include "random.h"
#include "iap.h"
#include "usb_app.h"
#include "nvsram.h"
#include "ucl.h"
#include "monitor.h"
#include "host_echo.h"
#include "usb_echo.h"
#include "nfc_spi.h"




u8 chksum_xor8(const u8 *data, u32 num);
u16 chksum_add16(u8 *dptr, u16 len);
u32 chksum_add32(u8 *dptr, u16 len);
void mem_cpy (void* dst, const void* src, int cnt) ;
void mem_set (void* dst, int val, int cnt) ;
int mem_cmp (const void* dst, const void* src, int cnt) ;

u8 queue_init(LinkQueue *Q);
u8 queue_add(LinkQueue *Q,QElemType e);
u8 queue_del(LinkQueue *Q);
u16 queue_item(LinkQueue *Q);
QElemType queue_get(LinkQueue *Q);

#endif	/*	_COMMON_H_H	*/

